package leetcode.网易笔试.a;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = sc.nextInt();

        }
        System.out.println(solution(nums));
    }
    static int max = Integer.MIN_VALUE;
    public static int solution(int[] nums){
        dfs(nums,0,0);
        if(max == 0){
            return -1;
        }
        return max;
    }

    public static void dfs(int[] nums,int sum,int index){
        if(index==nums.length){
            if(sum%6==0){
                max = Math.max(max,sum);
                return;
            }else{
                return;
            }
        }
        dfs(nums,sum+nums[index],index+1);
        dfs(nums,sum,index+1);
    }
}
